/*
 * @Description: 道具记录
 * @Author: iamsmiling
 * @Date: 2021-05-30 22:05:18
 * @LastEditTime: 2021-05-30 22:55:40
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/domain/local/prop/prop_kit_tab_entity.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class PropKitRecordController extends GetxController {
  int currentIndex = 0;

  switchTab(int index) {
    currentIndex = index;
    update();
    print(currentIndex);
  }
}

class PropKitRecordBody extends StatelessWidget {
  final List<PropRecordEntity> records;
  const PropKitRecordBody({Key? key, required this.records}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PropKitRecordController>(
        init: PropKitRecordController(),
        builder: (_) {
          return Container(
            child: Column(
              children: [
                Container(
                  color: R.color.fffcfcfc,
                  child: Container(
                    padding: EdgeInsets.only(
                        left: R.dimen.dp60,
                        top: R.dimen.dp20,
                        right: R.dimen.dp60,
                        bottom: R.dimen.dp18),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        GestureDetector(
                          behavior: HitTestBehavior.translucent,
                          onTap: () => _.switchTab(0),
                          child: Text(
                            "使用记录",
                            key: ObjectKey("使用记录"),
                            style: _.currentIndex == 0
                                ? TextStyle(
                                    fontSize: R.dimen.sp15,
                                    color: R.color.ff00c2ba,
                                    fontWeight: FontWeight.w600)
                                : TextStyle(
                                    fontSize: R.dimen.sp15,
                                    color: R.color.ff666666),
                          ),
                        ),
                        GestureDetector(
                          behavior: HitTestBehavior.translucent,
                          onTap: () => _.switchTab(1),
                          child: Text(
                            "获取记录",
                            key: ObjectKey("获取记录"),
                            style: _.currentIndex == 1
                                ? TextStyle(
                                    fontSize: R.dimen.sp15,
                                    color: R.color.ff00c2ba,
                                    fontWeight: FontWeight.w600)
                                : TextStyle(
                                    fontSize: R.dimen.sp15,
                                    color: R.color.ff666666),
                          ),
                        )
                      ],
                    ),
                  ),
                ),
                Expanded(
                    child: IndexedStack(
                  index: _.currentIndex,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        DefaultTextStyle(
                          style: TextStyle(
                              fontSize: R.dimen.sp15,
                              color: R.color.ff222222,
                              fontWeight: FontWeight.w600),
                          child: Container(
                            color: R.color.fffcfcfc,
                            width: R.dimen.width,
                            padding: EdgeInsets.only(
                                bottom: R.dimen.dp13,
                                left: R.dimen.dp12,
                                right: R.dimen.dp12),
                            child: Row(
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                Expanded(
                                  child: Text(
                                    "名称",
                                    textAlign: TextAlign.start,
                                  ),
                                ),
                                Expanded(
                                  child: Text(
                                    "使用数量",
                                    textAlign: TextAlign.start,
                                  ),
                                ),
                                Expanded(
                                  child: Text(
                                    "使用时间",
                                    textAlign: TextAlign.center,
                                  ),
                                )
                              ],
                            ),
                          ),
                        ),
                        Divider(height: 1),
                        Expanded(
                            child: ListView.separated(
                          padding:
                              EdgeInsets.symmetric(horizontal: R.dimen.dp12),
                          separatorBuilder: (BuildContext context, int i) {
                            return Divider(height: 1);
                          },
                          itemBuilder: (BuildContext context, int i) {
                            PropRecordEntity record = records[i];
                            return Container(
                              padding:
                                  EdgeInsets.symmetric(vertical: R.dimen.dp15),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Expanded(
                                    child: Text(
                                      record.label,
                                      textAlign: TextAlign.start,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp13,
                                          color: R.color.ff333333),
                                    ),
                                  ),
                                  Expanded(
                                    child: Text(
                                      "${record.count}",
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp13,
                                          color: R.color.ff111111),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 2,
                                    child: Text(
                                      record.date,
                                      textAlign: TextAlign.end,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp12,
                                          color: R.color.ff555555),
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                          itemCount: records.length,
                        ))
                      ],
                    ),
                    Column(
                      children: [
                        DefaultTextStyle(
                          style: TextStyle(
                              fontSize: R.dimen.sp15,
                              color: R.color.ff222222,
                              fontWeight: FontWeight.w600),
                          child: Container(
                            color: R.color.fffcfcfc,
                            width: R.dimen.width,
                            padding: EdgeInsets.only(
                                bottom: R.dimen.dp13,
                                left: R.dimen.dp12,
                                right: R.dimen.dp12),
                            child: Row(
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                Expanded(
                                  child: Text(
                                    "名称",
                                    textAlign: TextAlign.center,
                                  ),
                                ),
                                Expanded(
                                  child: Text(
                                    "方式",
                                    textAlign: TextAlign.center,
                                  ),
                                ),
                                Expanded(
                                  child: Text(
                                    "数量",
                                    textAlign: TextAlign.center,
                                  ),
                                ),
                                Expanded(
                                  child: Text(
                                    "获取时间",
                                    textAlign: TextAlign.center,
                                  ),
                                  flex: 2,
                                )
                              ],
                            ),
                          ),
                        ),
                        Divider(height: 1),
                        Expanded(
                            child: ListView.separated(
                          padding:
                              EdgeInsets.symmetric(horizontal: R.dimen.dp12),
                          separatorBuilder: (BuildContext context, int i) {
                            return Divider(height: 1);
                          },
                          itemBuilder: (BuildContext context, int i) {
                            PropRecordEntity record = records[i];
                            return Container(
                              padding:
                                  EdgeInsets.symmetric(vertical: R.dimen.dp15),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Expanded(
                                    child: Text(
                                      record.label,
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp13,
                                          color: R.color.ff333333),
                                    ),
                                  ),
                                  Expanded(
                                    child: Text(
                                      record.channel,
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp13,
                                          color: R.color.ff222222),
                                    ),
                                  ),
                                  Expanded(
                                    child: Text(
                                      "${record.count}",
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp13,
                                          color: R.color.ff111111),
                                    ),
                                  ),
                                  Expanded(
                                    flex: 2,
                                    child: Text(
                                      record.date,
                                      textAlign: TextAlign.center,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp12,
                                          color: R.color.ff555555),
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                          itemCount: records.length,
                        ))
                      ],
                    )
                  ],
                ))
              ],
            ),
          );
        });
  }
}
